package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.utils.ExcelUtil;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.system.domain.Project;
import com.ruoyi.system.service.IProjectService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 检测台账汇总 信息操作处理
 *
 * @author ruoyi
 * @date 2018-12-24
 */
@Controller
@RequestMapping("/system/project")
public class ProjectController extends BaseController {
    private String prefix = "system/project" ;

    @Autowired
    private IProjectService projectService;

    @RequiresPermissions("system:project:view")
    @GetMapping()
    public String project() {
        return prefix + "/project" ;
    }

    /**
     * 查询检测台账汇总列表
     */
    @RequiresPermissions("system:project:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Project project) {
        startPage();
        List<Project> list = projectService.selectProjectList(project);
        return getDataTable(list);
    }

    @PostMapping("/listByContractId")
    @ResponseBody
    public List<Project> listByContractId(Integer contractId) {
        Project project = new Project();
        project.setContractId(contractId);
        List<Project> list = projectService.selectProjectList(project);
        return list;
    }


    /**
     * 导出检测台账汇总列表
     */
    @RequiresPermissions("system:project:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Project project) {
        List<Project> list = projectService.selectProjectList(project);
        ExcelUtil<Project> util = new ExcelUtil<Project>(Project.class);
        return util.exportExcel(list, "project");
    }

    /**
     * 新增检测台账汇总
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add" ;
    }

    /**
     * 新增保存检测台账汇总
     */
    @RequiresPermissions("system:project:add")
    @Log(title = "检测台账汇总", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Project project) {
        return toAjax(projectService.insertProject(project));
    }

    /**
     * 修改检测台账汇总
     */
    @GetMapping("/edit/{projectId}")
    public String edit(@PathVariable("projectId") Integer projectId, ModelMap mmap) {
        Project project = projectService.selectProjectById(projectId);
        mmap.put("project", project);
        return prefix + "/edit" ;
    }

    /**
     * 修改保存检测台账汇总
     */
    @RequiresPermissions("system:project:edit")
    @Log(title = "检测台账汇总", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Project project) {
        return toAjax(projectService.updateProject(project));
    }

    /**
     * 删除检测台账汇总
     */
    @RequiresPermissions("system:project:remove")
    @Log(title = "检测台账汇总", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(projectService.deleteProjectByIds(ids));
    }

}
